//
//  WoFaYunDetailGoodListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/10/12.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "WoFaYunDetailGoodListCell.h"

@interface WoFaYunDetailGoodListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *listView;

@end

@implementation WoFaYunDetailGoodListCell

+ (instancetype)WoFaYunDetailGoodListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"WoFaYunDetailGoodListCell";
    WoFaYunDetailGoodListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[WoFaYunDetailGoodListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.titleLab];
        
        self.listView = [UIView new];
        self.listView.backgroundColor = HexColor(0xffffff);
        [self.bgView addSubview:self.listView];
    }
    return self;
}

-(void)setModel:(WoFaYunDetailModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.titleLab.nim_left = 10;
    self.titleLab.nim_top = 15;
    self.titleLab.text = @"货物清单";
    [self.titleLab sizeToFit];
    
    
    self.listView.nim_left = 10;
    self.listView.nim_top = 10 + self.titleLab.nim_bottom;
    self.listView.nim_width = self.bgView.nim_width - 2 * self.listView.nim_left;
    if (self.model.dp_nums.count) {
        self.listView.nim_height = (58 * self.model.dp_nums.count) + (5 * (self.model.dp_nums.count - 1));
    }else {
        self.listView.nim_height = 0;
    }
    
    
    [self.listView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    __block CGFloat viewTop = 0;
    [self.model.dp_nums enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, viewTop, self.listView.nim_width, 58)];
        view.backgroundColor = HexColor(0xF7F7FA);
        view.layer.masksToBounds = YES;
        view.layer.cornerRadius = 4;
        [self.listView addSubview:view];
        
        UIImageView *iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 20, 18, 18)];
        iconImgView.image = [UIImage imageNamed:@"wofayun_icon_form"];
        [view addSubview:iconImgView];
        
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(iconImgView.nim_right + 10, 13, view.nim_width - 15 - 24 - 10 - (iconImgView.nim_right + 10), 13)];
        titleLab.textColor = HexColor(0x9C9DB3);
        titleLab.font = [UIFont systemFontOfSize:12];
        titleLab.text = @"提货单号";
        [view addSubview:titleLab];
        
        UILabel *numLab = [[UILabel alloc] initWithFrame:CGRectMake(iconImgView.nim_right + 10, titleLab.nim_bottom + 2, titleLab.nim_width, 17)];
        numLab.textColor = HexColor(0x2B2C44);
        numLab.font = BoldFontOfSize(16);
        numLab.text = obj;
        [view addSubview:numLab];
        
        UIImageView *arrowImgView = [[UIImageView alloc] initWithFrame:CGRectMake(view.nim_width - 15 - 24, 17, 24, 24)];
        arrowImgView.image = [UIImage imageNamed:@"icon_staff_list_arrow"];
        [view addSubview:arrowImgView];
        
        UIButton *btn = [[UIButton alloc] initWithFrame:view.frame];
        btn.tag = idx;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:btn];
        
        viewTop = view.nim_bottom + 5;
    }];
    
    self.bgView.nim_height = self.listView.nim_bottom + 10;
    self.height = self.bgView.nim_bottom;
}

- (void)btnClick:(UIButton *)sender {
    if (self.listBlock) {
        self.listBlock(self.model.dp_nums[sender.tag]);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
